const fs = require("fs");
const path = require("path");
const http = require("http");
const server = http.createServer();
server.on("request", (req, res) => {
  const url = req.url;
  //   const fpath = path.join(__dirname,url)
  let fpath = "";
  if (url === "/") {
    fpath = path.join(__dirname, "/clock/index.html");
  } else {
    fpath = path.join(__dirname, "/clock", url);
  }
  console.log(fpath);
  fs.readFile(fpath, "utf8", (err, data) => {
    if (err) return console.log(err.message);
    res.end(data);
  });
});

server.listen(80, () => {
  console.log("启动服务器成功");
});
